package com.tan.controller;

import com.alibaba.fastjson.JSONObject;
import com.tan.domain.response.Result;
import com.tan.domain.response.StatusCode;
import com.tan.mapper.BlogMapper;
import com.tan.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @description:
 * @author: longshifu
 * @time: 2022/7/14 9:59
 */
@RestController
public class IndexController {
    @Autowired
    BlogService blogService;
    @Autowired
    BlogMapper blogMapper;


    @GetMapping("/getRecommendBlogList")
    public Result getRecommendBlogList() {
        return new Result(true, StatusCode.OK, "获取推荐博客成功", blogService.listRecommendBlogTop(8));
    }

    @GetMapping("/blog/{id}")
    public Result getBlogDetail(@PathVariable Long id) {
        System.out.println("博客详情： "+JSONObject.toJSON(blogService.getBlogDetail(id)));

        return new Result(true, StatusCode.OK, "获取博客详情成功", blogService.getBlogDetail(id));

    }

    @GetMapping("/footer/newblog")
    public Result newBlogs(){
        return new Result(true, StatusCode.OK, "获取推荐博客成功", blogService.listRecommendBlogTop(3));
    }

    @GetMapping("/blogs")
    public Result getBlogList(@RequestHeader Map<String,Object> para, @RequestParam String query, @RequestParam int pagenum, @RequestParam int pagesize) {
        JSONObject blogList = blogService.getAllBlogPage(pagenum, pagesize);
        return new Result(true, StatusCode.OK, "获取博客列表成功", blogList);
    }
}
